import { requestClient } from '#/api/request';

interface NewsMgrListParams {
  curPage: number;
  pageSize: number;
  subject?: string;  // 主题
  compId?: string;   // 大赛id
  groupId?: string;  // 组别id
  module?: string;   // 资讯类型
  publishStatus?: string; // 发布状态
}

interface NewsMgrListResponse {
  code: number;
  data: {
    list: {
      id: string; 
      img: string;
      content: string;
      sort: number;
      subject: string;
      intro: string;
      publishStatus: string;
      publishStatusContext: string;
      publishTime: string;
      module: string;
      tag: string;
      initialViews: number;
      initialVisitors: number;
      views: number;
      visitors: number;
      fileName: string;
      company: string;
      works: string;
      compId: string;
      groupId: string;
      creator: string;
      draft: string;
    }[];
    pageInfo: {
      total: number;
      pageNum: number;
      pageSize: number;
    };
  };
}

// 查询咨讯管理信息分页列表
export const getNewsMgrListApi = (params: NewsMgrListParams): Promise<NewsMgrListResponse> => {
  return requestClient.get('/match/get-consult-manager-info-list', {
    params,
  });
};

interface UpdateStatusNewsParams {
  id: string;
  publishStatus: boolean;
}

// 更新资讯状态
export const updateStatusNewsApi = (params: UpdateStatusNewsParams): Promise<any> => {
  return requestClient.patch('/match/update-status-consult-manager-info', params);
};

// 删除资讯
export const deleteNewsApi = (id: string): Promise<any> => {
  return requestClient.delete(`/match/delete-consult-manager-info/${id}`);
};

interface CreateNewsParams {
  id?: string;
  compId?: string;
  groupId?: string;
  subject?: string;
  intro?: string;
  module?: number;
  initialViews?: number;
  initialVisitors?: number;
  img?: string;
  sort?: number;
  content?: string;
  publishStatus?: boolean;
  publishTime?: string;
  tag?: string;
  fileName?: string;
  company?: string;
  works?: string;
  createUser?: string;
  draft?: string | null;
}

// 创建资讯
export const createNewsApi = (params: CreateNewsParams): Promise<any> => {
  return requestClient.post('/match/create-consult-manager-info', params);
};

// 修改资讯
export const updateNewsApi = ( params: CreateNewsParams): Promise<any> => {
  return requestClient.post(`/match/update-consult-manager-info`, params);
};

// 资讯详情
export const getNewsDetailApi = (id: string): Promise<any> => {
  return requestClient.get(`/match/open/get-consult-manager-info-detail/${id}`); 
};
